qui(
    function (require, exports, module) {
        VODNew.Evt = {
            InitBindEvt: function () {
                // 显示小窗口视频预览
                var playOneInfo = VODNew.Dao.playOneInfo;
                $("#makedImg").on("mouseenter mouseleave", "img", function (event) {
                    var self = $(this);
                    if (event.type == 'mouseenter') {
                        playOneInfo.mouseenter = true;
                        playOneInfo.left = self.offset().left - $("#play-one").width();
                        playOneInfo.top = self.offset().top;
                        playOneInfo.time = self.attr("id").split("-")[1];
                    } else if (event.type == 'mouseleave') {
                        playOneInfo.mouseenter = false;
                        $("#play-one").hide();
                    }
                });
                $(".cVideo").click(function () {
                    if ($(this).attr('data') == 'cover-program') {
                        $("#cover-program-cfm").css('display', "inline");
                    } else {
                        $("#cover-program-cfm").hide();
                    }
                });
                $('#ase-close').on('click', function () {
                    VODNew.AccurateFrame.accurateStartEndRemove()
                });
            },

            // 显示和隐藏打点打条列表
            ShowAndHideSegmentationList: function (mode) {
                var list = $(".segmentation").find("div[dname=segmentation_div]");
                var aTag = $("a[action-name=segmentation]");

                if (mode == "close") {
                    list.hide();
                    list.attr("data-show", "false");
                    if (!aTag.hasClass("segmentation_grey")) {
                        aTag.addClass("segmentation_grey");
                    }
                } else {
                    this.ShowAndHideSegmentationAssistList("close");
                    if (list.attr("data-show") == "false") {
                        list.show();
                        list.attr("data-show", "true");
                        aTag.removeClass("segmentation_grey")
                    } else {
                        list.hide();
                        list.attr("data-show", "false");
                        if (!aTag.hasClass("segmentation_grey")) {
                            aTag.addClass("segmentation_grey");
                        }
                    }
                }
            },
            ShowAndHideSegmentationAssistList: function (mode) {
                var list = $(".segmentation").find("div[dname=segmentation-assist_div]");
                var aTag = $("a[action-name=segmentation-assist]")
                if (mode == "close") {
                    list.hide();
                    list.attr("data-show", "false");
                    if (!aTag.hasClass("segmentation_grey")) {
                        aTag.addClass("segmentation_grey");
                    }
                } else {
                    this.ShowAndHideSegmentationList("close");
                    if (list.attr("data-show") == "false") {
                        list.show();
                        list.attr("data-show", "true");
                        aTag.removeClass("segmentation_grey")
                    } else {
                        list.hide();
                        list.attr("data-show", "false");
                        if (!aTag.hasClass("segmentation_grey")) {
                            aTag.addClass("segmentation_grey");
                        }
                    }
                }
            },

            // 打开关闭背景颜色
            OpenOrCloseBk: function (self) {
                if (!self.hasClass("switch-position")) {
                    self.addClass("switch-position");
                    VODNew.Dao.storageData('BCS', 'on');
                    $('.fragment-img').removeClass('c000');
                    $('.in-out-mark-s').show();
                } else {
                    self.removeClass("switch-position");
                    VODNew.Dao.storageData('BCS', 'off');
                    $('.fragment-img').addClass('c000');
                    $('.in-out-mark-s').hide();
                }
            },
            doFragmentSubmitRemind: function () {
                var numTime = parseInt($('#picNum').text());
                var totalLength = $("#div_fragment_append").children().length;
                var fragmentElementDiv = $("div[fragment-line='" + totalLength + "']")
                var st = parseInt(fragmentElementDiv.find("input:eq(0)").val());
                if (st >= numTime - 1) {
                    console.log("reach end , need not remind");
                    return
                }
                var et1 = st + 750;
                var et2 = (numTime - 1) - 150;//约5分钟前
                var et = et2 > et1 ? et2 : et1;
                if (et > numTime - 1) {
                    et = numTime - 1
                }
                $("#fragment-dlg").dialog("open");
                $("#fragment-dlg").find("img:eq(0)").attr("src", $("#img-" + st).attr("src"));
                $("#fragment-dlg").find("img:eq(1)").attr("src", $("#img-" + et).attr("src"));
                $("#fragment-dlg").find("span:eq(0)").html(st);
                $("#fragment-dlg").find("span:eq(1)").html(et);
            },
            transToFpTime: function (period) {
                var second = period % 60;
                var minute = ( period % 3600 - period % 60) / 60;
                var hour = (period - period % 3600) / 3600;
                return (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second);
            },

            // 定时提醒
            RegularTimeRemind: function () {
                var regularTime = $("#alert-time").val();

                if (regularTime && regularTime != "undefined") {
                    (function () {
                        var compareTimeRt = -1, //时间比较结果
                        //blinkTimes = 0,     //闪烁次数
                        //settedTime = '',
                            isTimeArriveInt = null;
                        $("#alert-pop").attr("disabled", "disabled");

                        //alert("添加成功");
                        VODNew.Plugin.tips("success", '添加成功');

                        var isTimeArrive = function () {
                            var time = $("#alert-time").val();
                            var now = new Date();
                            var nowStr = VODNew.Util.formatDateTimeFormat(now);
                            compareTimeRt = VODNew.Util.compareTime(time, nowStr);
                        };

                        var titleWink = function () {
                            // blinkTimes++;
                            //if(blinkTimes==3){blinkTimes=1}

                            if (compareTimeRt >= 0) {
                                window.focus();
                                alert('【' + VODNew.Dao.getParamsData().channel_name + '】【' + regularTime + '】预定时间已到!');
                                $("#alert-pop").removeAttr("disabled");
                                $("#alert-time").val("");
                                clearInterval(isTimeArriveInt);
                                return;
                            }
                            setTimeout(titleWink, 200);
                        };

                        isTimeArriveInt = setInterval(isTimeArrive, 200);
                        //settedTime = time;
                        titleWink();

                    })();
                } else {
                    //alert("时间不能为空");
                    VODNew.Plugin.tips("error", '时间不能为空');
                }
            },

            globalEvent: function (e) {
                console.log("e.keyCode", e.keyCode);
                var self = this;
                var settings = VODNew.Dao.settings;
                var global = VODNew.Config.Global;

                // textarea去除快捷键
                if ($('textarea').is(":focus")) {
                    return true;
                }
                if ($('input').is(":focus")) {
                    return true;
                }

                if (e.which == VODNew.Config.KEY_CODE.ESC) { // 打点精确化,调出该图片所有上所对应的所有帧  对应快捷键为 ESC
                    VODNew.AccurateFrame.accurateStartEndRemove();
                    return false;
                }

                if (this.checkDlgOpen(e)) {
                    return true;
                }
                // 文本框去除快捷键
                if ($("#cForm,#dForm").find('input[type=text]').is(":focus")) {
                    return true;
                }
                if (e.which == VODNew.Config.KEY_CODE.SPACE) { //播放器 播放/暂停
                    e.preventDefault();
                    VODCom.Player.changePlayPause( "flash" );
                    return true;
                }
                if (e.which == VODNew.Config.KEY_CODE.G &&  VODNew.Config.GREY_MODE.inRange ) { //查看标题自动识别
                    //$("button[name=btn_submit_fragment]:visible")
                    $("button[name=btn_get_auto_title]").click();
                    return true;
                }

                if (e.which == VODNew.Config.KEY_CODE.Y) { //提交分片
                    //$("button[name=btn_submit_fragment]:visible")
                    VODNew.Util.doShortcutFragmentSubmit();
                    return true;
                }

                if (e.which == VODNew.Config.KEY_CODE.B) { //清除收纳
                    VODCom.Pic.clear();
                    return true;
                }

                if (e.which == VODNew.Config.KEY_CODE.ZERO && e.ctrlKey) {
                    $('[role="alert"]').hide();
                    return true;
                }

                if (e.which == VODNew.Config.KEY_CODE.Z) { //提交删除
                    VODNew.Advert.del_submit();
                    return true;
                }

                if (e.which == VODNew.Config.KEY_CODE.A) { //提交打点
                    VODNew.Util.dot_submit()
                    $('#addInfo').removeAttr('disabled').html('提交');
                    return true;
                }
                var redParent = $('.red').parent();
                var red = $('.red').parent().find("div");

                if (e.which == VODNew.Config.KEY_CODE.V) { //删除开始
                    if (settings.stime >= 0) {
                        if (redParent.find('.ad-l') > 0 || redParent.find('.p-r').length > 0 || redParent.find('.p-l').length > 0) {
                            return false;
                        }
                        $('.ad-l').remove();
                        if (!$('.old').hasClass('ad-l') && !$('.old').hasClass('ad-r')) {
                            $('.old').remove();
                        }
                        $('.red').addClass('ad-l');
                        $('.ad-l').removeClass('ad-r');
                        $('.ad-l').html("广<br />告<br />头");
                        $('input[name=d_sTime]').val(settings.stime);
                    }
                    return true;
                }
                if (e.which == VODNew.Config.KEY_CODE.C) { //删除结束
                    if (settings.etime >= 0) {

                        if (redParent.find('.ad-r').length > 0 || redParent.find('.p-r').length > 0 || redParent.find('.p-l').length > 0) {
                            return false;
                        }
                        var tmp_stime = $('input[name=d_sTime]').val();
                        if (tmp_stime.length && parseInt(tmp_stime) > parseInt(settings.etime)) {
                            //alert('起始帧不能大于结束帧!');
                            VODNew.Plugin.tips("error", "起始帧不能大于结束帧");
                            return false;
                        }
                        $('.ad-r').remove();
                        if (!$('.old').hasClass('ad-r') && !$('.old').hasClass('ad-l')) {
                            $('.old').remove();
                        }
                        $('.red').addClass('ad-r');
                        $('.ad-r').removeClass('ad-l');
                        $('.ad-r').html("广<br />告<br />尾");
                        $('input[name=d_eTime]').val(settings.etime);
                    }
                    return true;
                }
                if (red.length > 0) {
                    if (e.which == VODNew.Config.KEY_CODE.T) { //分片终点
                        VODNew.Util.doShortcutSetFragmentEnd();
                        return true;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.M) { //打收纳头
                        VODCom.Pic.recordStart();
                        return true;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.N) { //打收纳尾
                        VODCom.Pic.recordEnd();
                        return true;
                    }

                    var skip = redParent.find('.ad-r').length > 0 || redParent.find('.ad-l').length > 0
                    if (e.which == VODNew.Config.KEY_CODE.F) { //打开始
                        if (VODNew.Util.isAppendFragmentMode()) {
                            return false;
                        }
                        if (skip) {
                            return true;
                        }
                        VODCom.NewsHighlight.setNewStart()
                        return;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.D) { //打结束
                        if (skip) {
                            return true;
                        }
                        VODCom.NewsHighlight.setNewEnd();
                        VODNew.Util.fillDefaultTitle();
                        return;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.S) { //打封面
                        if (skip) {
                            return true;
                        }
                        VODCom.NewsHighlight.setNewImage()
                        return;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.R) { //标题ocr识别
                        VODNew.MarkOcrManager.doMarkOcrImage();
                        return;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.LEFT_SQUARE_BRACKET) {
                        VODCom.NewsHighlight.setMaskStart();
                        return;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.RIGHT_SQUARE_BRACKET) {
                        VODCom.NewsHighlight.setMaskEnd();
                        return;
                    }
                    if (e.which == VODNew.Config.KEY_CODE.BACKSLASH) {
                        VODNew.MaskManager.modifyMaskEntity();
                        return;
                    }
                }

                if (e.which == VODNew.Config.KEY_CODE.Q) { // 打点精确化,调出该图片所有上所对应的所有帧  对应快捷键为 q
                    if (!e.altKey) {
                        VODNew.AccurateFrame.handler_keyCodeQ();
                    } else {
                        VODNew.MaskManager.addMaskEntity()
                    }
                    return true;
                }
                if (e.keyCode == VODNew.Config.KEY_CODE.W) // 鼠标悬浮快捷键w
                {
                    var playOneInfo = VODNew.Dao.playOneInfo;
                    if (playOneInfo.mouseenter == true) {
                        VODCom.Player.updatePosition({left: playOneInfo.left, top: playOneInfo.top})
                        VODCom.Player.viewOne(playOneInfo.time);
                    }
                    return true;
                }

                if (e.keyCode == VODNew.Config.KEY_CODE.X) // ocr快捷键 x
                {
                    VODNew.Evt.ShowAndHideSegmentationList();
                    return true;
                }
                if (e.keyCode == VODNew.Config.KEY_CODE.E) // ocr快捷键 E
                {
                    VODNew.Evt.ShowAndHideSegmentationAssistList();
                    return true;
                }
                if (e.keyCode == VODNew.Config.KEY_CODE.LEFT) { //左
                    VODNew.Util.dealDirectionKey(VODNew.Config.KEY_CODE.LEFT, settings);
                    return false;
                }
                if (e.keyCode == VODNew.Config.KEY_CODE.RIGHT) { //右
                    VODNew.Util.dealDirectionKey(VODNew.Config.KEY_CODE.RIGHT, settings);
                    return false;
                }
                if (e.keyCode == VODNew.Config.KEY_CODE.UP) { //上
                    VODNew.Util.dealDirectionKey(VODNew.Config.KEY_CODE.UP, settings);
                    return false;
                }
                if (e.keyCode == VODNew.Config.KEY_CODE.DOWN) { //下
                    VODNew.Util.dealDirectionKey(VODNew.Config.KEY_CODE.DOWN, settings);
                    return false;
                }
                return true;
            },
            checkDlgOpen:function(){
                if (VODNew.AccurateFrame.isDlgOpen()) {
                    console.log(" VODNew.AccurateFrame is open");
                    return true;
                }
                var temp = [];
                temp.push("#auto_title-dlg");
                temp.push("#image_mark-dlg");
                temp.push("#fragment-dlg");
                temp.push("#image_mask-dlg");
                temp.push("#epg_alert_dlg");
                temp.push("#epg_confirm_dlg");
                var needBreak = false;
                $.each( temp,function(i,elemt){
                    if ($(elemt).is(":visible")) {
                        console.log(elemt + "  is open");
                        needBreak = true;
                        return false
                    }
                } );
                if(needBreak){
                    return true;
                }
                return false
            }
        };

    }
);